import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

public class App {

    public static void main(String[] args) {

        //得到spring的上下文
        ApplicationContext context  = new ClassPathXmlApplicationContext("spring-config.xml");
        System.out.println("得到 spring 之后!");
        //获取某个bean
        User user = (User)context.getBean("user");
        User user2 = context.getBean("user2",User.class);
        //调用相应的方法
        System.out.println(user.sayHi());
        System.out.println(user2.sayHi());
        System.out.println("ApplicationContext 结束!");
        BeanFactory factory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));
        User user3 = (User)factory.getBean("user");
        System.out.println(user.sayHi());


    }
}
